package com.wyd.jwpkglxt_ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wyd.jwpkglxt_ssm.entity.Classroom;
import com.wyd.jwpkglxt_ssm.dao.ClassroomDao;
import com.wyd.jwpkglxt_ssm.service.ClassroomService;
import org.springframework.stereotype.Service;

import org.springframework.beans.factory.annotation.Autowired;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * (Classroom)表服务实现类
 *
 * @author wyd
 * @since 2021-08-02 17:34:01
 */
@Service("classroomService")
public class ClassroomServiceImpl implements ClassroomService {
    @Autowired
    private ClassroomDao classroomDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Classroom queryById(Integer id) {
        return this.classroomDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Classroom> queryAllByLimit(int offset, int limit) {
        return this.classroomDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param classroom 实例对象
     * @return 实例对象
     */
    @Override
    public Classroom insert(Classroom classroom) {
        this.classroomDao.insert(classroom.setCreateTime(new Timestamp(new Date().getTime())));
        return classroom;
    }

    /**
     * 修改数据
     *
     * @param classroom 实例对象
     * @return 实例对象
     */
    @Override
    public Classroom update(Classroom classroom) {
        this.classroomDao.update(classroom.setUpdateTime(new Timestamp(new Date().getTime())));
        return this.queryById(classroom.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.classroomDao.deleteById(id) > 0;
    }

    @Override
    public PageInfo<Classroom> queryAllByPage(Integer pageNum, Integer pageSize, Classroom classroom) {
        PageHelper.startPage(pageNum,pageSize);
        List<Classroom> classrooms = this.classroomDao.queryAll(classroom);
        return new PageInfo<>(classrooms);
    }

    @Override
    public Boolean deleteClassroomBatch(List<Integer> classroomIds) {
        return this.classroomDao.deleteClassroomBatch(classroomIds) > 0;
    }

    @Override
    public int updateStatusBatch(List<Integer> classroomIds, Integer status) {
        return this.classroomDao.updateStatusBatch(classroomIds,status,new Timestamp(new Date().getTime()));
    }

    @Override
    public List<Classroom> queryAll(Classroom classroom) {
        return this.classroomDao.queryAll(classroom);
    }
}